import QtQuick 2.12
import QtQuick.Controls 2.12

Rectangle {
    width: 759
    height: 100
    color: "transparent"
    radius: 5
    property int currentIndex: 0
    // 警告和异常信息列表
    property var warningsAndErrors: [
        {type: "车载控制器与操控台控制器通讯故障", active: can_manager.error_communication_vehicle_controller_and_console_controller, color: "#F05252"},
        {type: "防碰撞限动报警", active: can_manager.error_anticollision_limited_action, color: "#D79B00"},
        {type: "IMU通讯故障", active: can_manager.error_communication_imu, color: "#F05252"},
        {type: "双轴倾角传感器通讯故障", active: can_manager.error_communication_biaxial_inclination_sensor, color: "#F05252"},
        {type: "车载工控机与车载控制器通讯故障", active: can_manager.error_communication_vehicle_pc_and_vehicle_controller, color: "#F05252"},
        {type: "左手柄通讯故障", active: can_manager.error_communication_left_handle, color: "#F05252"},
        {type: "右手柄通讯故障", active: can_manager.error_communication_right_handle, color: "#F05252"},
        {type: "左按钮板通讯故障", active: can_manager.error_communication_left_button_borad, color: "#F05252"},
        {type: "右前按钮板通讯故障", active: can_manager.error_communication_right_front_button_board, color: "#F05252"},
        {type: "发动机通讯故障", active: can_manager.error_communication_engine, color: "#F05252"},
        {type: "右后按钮板通讯故障", active: can_manager.error_communication_right_back_button_board, color: "#F05252"},
        {type: "车载控制器与操控台工控机通讯故障", active: can_manager.error_communication_vehicle_controller_and_console_pc, color: "#F05252"},
        {type: "发动机空滤堵塞报警", active: can_manager.error_engine_air_filter_clogged, color: "#D79B00"},
        {type: "液压油油位低报警", active: can_manager.error_low_hydraulic_oil_level, color: "#D79B00"},
        {type: "变速箱油油位低报警", active: can_manager.error_low_transmission_oil_level, color: "#D79B00"},
        {type: "燃油液位低报警", active: can_manager.error_low_fuel_level, color: "#D79B00"},
        {type: "液压油温高报警", active: can_manager.error_high_hydraulic_oil_temperature, color: "#D79B00"},
        {type: "左前超声波雷达连接故障", active: can_manager.error_connection_left_front_ultrasonic_radar, color: "#F05252"},
        {type: "左后超声波雷达连接故障", active: can_manager.error_connection_left_back_ultrasonic_radar, color: "#F05252"},
        {type: "右前超声波雷达连接故障", active: can_manager.error_connection_right_front_ultrasonic_radar, color: "#F05252"},
        {type: "右后超声波雷达连接故障", active: can_manager.error_connection_right_back_ultrasonic_radar, color: "#F05252"},
        {type: "转角角位移传感器连接故障", active: can_manager.error_connection_corner_angle_displacement_sensor, color: "#F05252"},
        {type: "动臂角位移传感器连接故障", active: can_manager.error_connection_arm_angle_displacement_sensor, color: "#F05252"},
        {type: "铲头角位移传感器连接故障", active: can_manager.error_connection_bucket_angle_displacement_sensor, color: "#F05252"},
        {type: "车速传感器故障", active: can_manager.error_speed_sensor, color: "#F05252"},
        {type: "前激光雷达通信故障", active: can_manager.error_communication_front_lidar, color: "#F05252"},
        {type: "后激光雷达通信故障", active: can_manager.error_communication_back_lidar, color: "#F05252"},
        {type: "左转电磁阀断路", active: can_manager.error_solenoid_valve_disconnected_turn_left, color: "#F05252"},
        {type: "右转电磁阀断路", active: can_manager.error_solenoid_valve_disconnected_turn_right, color: "#F05252"},
        {type: "动臂上升电磁阀断路", active: can_manager.error_solenoid_valve_disconnected_arm_up, color: "#F05252"},
        {type: "动臂下降电磁阀断路", active: can_manager.error_solenoid_valve_disconnected_arm_down, color: "#F05252"},
        {type: "铲斗装载电磁阀断路", active: can_manager.error_solenoid_valve_disconnected_bucket_up, color: "#F05252"},
        {type: "铲斗卸载电磁阀断路", active: can_manager.error_solenoid_valve_disconnected_bucket_down, color: "#F05252"},
        {type: "网络延时故障", active: can_manager.error_network_latency, color: "#F05252"},
        {type: "低电压报警", active: can_manager.error_low_voltage, color: "#D79B00"},
        {type: "车身倾斜报警", active: can_manager.error_vehicle_lean, color: "#D79B00"},
        {type: "前进电磁阀故障", active: can_manager.error_solenoid_valve_forward, color: "#F05252"},
        {type: "后退电磁阀故障", active: can_manager.error_solenoid_valve_back, color: "#F05252"},
        {type: "前激光雷达镜面污染", active: can_manager.error_front_lidar_mirror_contamination, color: "#D79B00"},
        {type: "后激光雷达镜面污染", active: can_manager.error_back_lidar_mirror_contamination, color: "#D79B00"},
        {type: "安全门A通讯报警", active: can_manager.error_communication_safety_door_a, color: "#D79B00"},
        {type: "安全门B通讯报警", active: can_manager.error_communication_safety_door_b, color: "#D79B00"},
        {type: "安全门A入侵报警", active: can_manager.error_invasions_safety_door_a, color: "#D79B00"},
        {type: "安全门B入侵报警", active: can_manager.error_invasions_safety_door_b, color: "#D79B00"}
    ]
    Timer {
        interval: 2000
        running: true
        repeat: true
        onTriggered: {
            do {
                currentIndex = (currentIndex + 1) % warningsAndErrors.length;
            } while (!warningsAndErrors[currentIndex].active && warningsAndErrors.some(item => item.active))
        }
    }

    Rectangle {
        id: warningBox
        anchors.fill: parent 
        radius: 8
        color: warningsAndErrors[currentIndex].color
        visible: warningsAndErrors.some(item => item.active)
        Image{
            id:warn_and_err_img
            anchors.left: parent.left
            anchors.leftMargin: 24
            anchors.verticalCenter: parent.verticalCenter
            height: 48
            width: 48
            source: warningsAndErrors[currentIndex].color === "#D79B00" ? "qrc:/imgs/warn_4.png" : "qrc:/imgs/close_7.png"
        }
        Text {
            anchors.left: warn_and_err_img.right
            anchors.verticalCenter: parent.verticalCenter
            anchors.leftMargin: 16
            text: warningsAndErrors[currentIndex].type
            color: "#FFFFFF"
            font.bold: true
            font.pixelSize: 40
        }
    }
}